package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.query.album.AlbumInfoQuery;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.SearchService;
import com.atguigu.tingshu.vo.search.AlbumSearchResponseVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search")
@SuppressWarnings({"all"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;


    /**
     * 仅用于测试业务逻辑-将指定专辑上架到索引库
     *
     * @param albumId
     * @return
     */

    @Operation(summary = "仅用于测试业务逻辑-将指定专辑上架到索引库")
    @GetMapping(value = "/albumInfo/upperAlbum/{albumId}")
    public Result upperAlbum(@PathVariable Long albumId){
        searchService.upperAlbum(albumId);
        return Result.ok();
    }

    /***
     *
     * 下架专辑-删除文档
     * @param albumId
     * @return
     */
    @Operation(summary = "下架专辑-删除文档")
    @GetMapping(value = "/albumInfo/lowerAlbum/{albumId}")
    public Result lowerAlbum(@PathVariable Long albumId){
        searchService.lowerAlbum(albumId);
        return Result.ok();
    }

    /***
     * 关键字索引热门专辑
     * @param albumIndexQuery
     * @return
     */
    @Operation(summary = "站内检索，支持关键字、分类、标签条件分页检索，结果高亮")
    @PostMapping(value = "/albumInfo")
    public Result<AlbumSearchResponseVo> search (@RequestBody AlbumIndexQuery albumIndexQuery){
        AlbumSearchResponseVo albumSearchResponseVo =  searchService.search(albumIndexQuery);
        return Result.ok(albumSearchResponseVo);
    }

    /***
     *
     * 查询指定一级分类下热门排行专辑
     * @param category1Id
     * @return
     */
    @Operation(summary = "查询指定一级分类下热门排行专辑")
    @GetMapping(value = "/albumInfo/channel/{category1Id}")
    public Result<List<Map<String,Object>>> getTopCategoryAlbumList(@PathVariable Long category1Id){
        List<Map<String,Object>> map = searchService.getTopCategoryAlbumList(category1Id);
        return Result.ok(map);
    }



}

